function checkExecutableSkill_ShowDown(obj)  
{

	if (!obj) return false;

	local isUseSkill = obj.sq_IsUseSkill(SKILL_SHOW_DOWN );
	if (isUseSkill) 
	{

		obj.getVar("GLOBAL_PARAMETER_CANCEL").set_vector(0,0);
		local pIntVec = sq_GetGlobalIntVector();
		sq_IntVectorClear(pIntVec);
		sq_IntVectorPush(pIntVec, 0);			
		obj.addSetStatePacket(STATE_SHOW_DOWN , pIntVec,  STATE_PRIORITY_USER, false, "");

		return true;
	}
	return false;
}

function checkCommandEnable_ShowDown(obj)
{


	return true;
}

function onEndState_ShowDown(obj,new_state)
{

	if (new_state != STATE_SHOW_DOWN)
	{
	

		obj.setShowEquipmentLayer(ENUM_EQUIPMENTTYPE_WEAPON, true);


	}

}


function preLoad_ShowDown(obj)
{
	local level = sq_GetSkillLevel(obj, SKILL_SHOW_DOWN);
	if (level > 0)
	{

		createFristAnimationPooledObject(obj,
		"character/swordman/effect/animation/atshowdown/1st/showdown1stwirefront_00.ani");
		createFristAnimationPooledObject(obj,
		"character/swordman/effect/animation/atshowdown/1st/showdown1stfront_00.ani");
		createFristAnimationPooledObject(obj,
		"character/swordman/effect/animation/atshowdown/1st/showdown1stwireback_00.ani");
		createFristAnimationPooledObject(obj,
		"character/swordman/effect/animation/atshowdown/1st/showdown1stback_00.ani");
		createFristAnimationPooledObject(obj,
		"character/swordman/effect/animation/atshowdown/2st/showdown2stwireback_00.ani");
		createFristAnimationPooledObject(obj,
		"character/swordman/effect/animation/atshowdown/2st/showdown2stwirefront_00.ani");
		createFristAnimationPooledObject(obj,
		"character/swordman/effect/animation/atshowdown/3st/showdown3stback_00.ani");
		createFristAnimationPooledObject(obj,
		"character/swordman/effect/animation/atshowdown/3st/showdown3stwirefront_00.ani");
		createFristAnimationPooledObject(obj,
		"character/swordman/effect/animation/atshowdown/3st/showdown3stfront_00.ani");
		createFristAnimationPooledObject(obj,
		"character/swordman/effect/animation/atshowdown/3st/showdown3stcover_00.ani");

	}
}

function onSetState_ShowDown(obj, state, datas, isResetTimer)
{

	obj.sq_StopMove();
	local state = obj.sq_GetVectorData(datas, 0);
	obj.setSkillSubState(state);
	if (state == 0)
	{
		obj.setShowEquipmentLayer(ENUM_EQUIPMENTTYPE_WEAPON, false);
		obj.sq_SetCurrentAnimation( CUSTOM_ANI_SHOW_DOWN_1ST );
		obj.flashScreenOnlyMe(obj,[200,1800,2000],[0,0,0,178],2);
		obj.getVar("dama2").clear_obj_vector();
		
		obj.sq_SetCurrentAttackInfo( ATTACKINFO_SHOW_DOWN_WIRE_ATTACK );

		local attackInfo = sq_GetCurrentAttackInfo(obj);
        local power = obj.sq_GetPowerWithPassive(SKILL_SHOW_DOWN , STATE_SHOW_DOWN , 0,-1,1.0);	 
        sq_SetCurrentAttackPower(attackInfo, power );

	
	}else if (state == 1)
	{
		obj.sq_SetCurrentAnimation( CUSTOM_ANI_SHOW_DOWN_2ST );
		createShowDown2ST_Back(obj);
		createShowDown2ST_Front(obj);
		
	}else if (state == 2)
	{
		obj.sq_SetCurrentAnimation( CUSTOM_ANI_SHOW_DOWN_3ST );

		obj.sq_SetCurrentAttackInfo( ATTACKINFO_SHOW_DOWN_FINISH );

		local attackInfo = sq_GetCurrentAttackInfo(obj);
        local power = obj.sq_GetPowerWithPassive(SKILL_SHOW_DOWN , STATE_SHOW_DOWN , 1,-1,1.0);	 
        sq_SetCurrentAttackPower(attackInfo, power );

	}

	obj.getVar("flag").clear_vector();
	obj.getVar("flag").push_vector(0);
	obj.getVar("flag").push_vector(0);
	obj.getVar("flag").push_vector(0);
	obj.getVar("flag").push_vector(0);	

}



function onProc_ShowDown(obj)
{
	local state = obj.getSkillSubState();

	if (state == 0)
	{
		local pAni = obj.sq_GetCurrentAni();
		local frmIndex = obj.sq_GetCurrentFrameIndex(pAni);

		local currentT = sq_GetCurrentTime(pAni);
		
		if (sq_IsEnd(pAni) == ture)
		{
			local pIntVec = sq_GetGlobalIntVector();
			sq_IntVectorClear(pIntVec);
			sq_IntVectorPush(pIntVec, 1);			
			obj.addSetStatePacket(STATE_SHOW_DOWN , pIntVec,  STATE_PRIORITY_USER, false, "");

		}else 
		{
			if (frmIndex >= 5 && obj.getVar("flag").get_vector(0) == 0)
			{
				obj.getVar("flag").set_vector(0,1);
				obj.sq_setShakeOnlyMe(obj,8,200);
				createShowDown1ST_Front(obj);
				
				createShowDown1ST_Back(obj);
				createShowDown1ST_Back2(obj);
				createShowDown1ST_Front2(obj);
				
				
			}
		}
	}else if (state == 1)
	{
		local pAni = obj.sq_GetCurrentAni();
		local frmIndex = obj.sq_GetCurrentFrameIndex(pAni);

		local currentT = sq_GetCurrentTime(pAni);
		
		if (sq_IsEnd(pAni) == ture)
		{
			local pIntVec = sq_GetGlobalIntVector();
			sq_IntVectorClear(pIntVec);
			sq_IntVectorPush(pIntVec, 2);			
			obj.addSetStatePacket(STATE_SHOW_DOWN , pIntVec,  STATE_PRIORITY_USER, false, "");

		}
	}else if (state == 2)
	{
		local pAni = obj.sq_GetCurrentAni();
		local frmIndex = obj.sq_GetCurrentFrameIndex(pAni);

		local currentT = sq_GetCurrentTime(pAni);
		
		if (sq_IsEnd(pAni) == ture)
		{
			local pIntVec = sq_GetGlobalIntVector();
			sq_IntVectorClear(pIntVec);
			sq_IntVectorPush(pIntVec, 2);			
			obj.addSetStatePacket(0 , pIntVec,  STATE_PRIORITY_USER, false, "");

			sq_SendMessage(obj,OBJECT_MESSAGE_INVINCIBLE,1,0);
			sq_PostDelayedMessage(obj,OBJECT_MESSAGE_INVINCIBLE,0,0,500 );

		}else
		{
		
			if (frmIndex >= 5 && obj.getVar("flag").get_vector(0) == 0)
			{
				obj.getVar("flag").set_vector(0,1);
				obj.sq_setShakeOnlyMe(obj,20,300);
				createShowDown3ST_Back2(obj);
				createShowDown3ST_Back(obj);
				createShowDown3ST_Front(obj);
				createShowDown3ST_Front2(obj);
				createShowDown3ST_Cover(obj);
				
			}

			if (frmIndex >= 6 && obj.getVar("flag").get_vector(1) == 0)
			{
				obj.getVar("flag").set_vector(1,1);
				
				obj.flashScreenOnlyMe(obj,[0,30,50],[255,255,255,255],6);
				
				removeShowDownHoldSuperEffect(obj);
				
			}

		}
	}
}


function onAttack_ShowDown(obj, damager, boundingBox, isStuck)
{

	local state = obj.getSkillSubState();
	if (state == 0)
	{

		if (damager.isObjectType(OBJECTTYPE_ACTIVE))
		{
			obj.getVar("dama2").push_obj_vector( damager );
			
			local masterAppendage = CNSquirrelAppendage.sq_AppendAppendage(damager, obj, SKILL_BLACK_OUT , 
			false, 
			"character/atswordman/showdown/ap_showdown.nut", true);		

			//appendage
		}
	}
}

function removeShowDownHoldSuperEffect(obj)
{

	local var = obj.getVar("dama2");  		
	local objectsSize = var.get_obj_vector_size();
	if (objectsSize > 0)
	{

		for(local i=0;i<objectsSize;++i)
		{
			local damager = var.get_obj_vector(i);
			if (damager)
				CNSquirrelAppendage.sq_RemoveAppendage(damager, "character/atswordman/showdown/ap_showdown.nut");		
		}
	}

}

function createShowDown1ST_Front(obj)
{
	if(!obj || !sq_IsMyControlObject(obj) )
	return ;

	local ani = sq_CreateAnimation("","character/swordman/effect/animation/atshowdown/1st/showdown1stwirefront_00.ani");
	local pooledObj = sq_CreatePooledObject(ani,true);
	//pooledObj = sq_SetEnumDrawLayer(pooledObj, ENUM_DRAWLAYER_BOTTOM);
	pooledObj.setCurrentPos(obj.getXPos() ,obj.getYPos() + 2,obj.getZPos() );
	pooledObj.setCurrentDirection(obj.getDirection());
	sq_AddObject(obj,pooledObj,2,false);	
}



function createShowDown1ST_Front2(obj)
{
	if(!obj || !sq_IsMyControlObject(obj) )
	return ;

	local ani = sq_CreateAnimation("","character/swordman/effect/animation/atshowdown/1st/showdown1stfront_00.ani");
	local pooledObj = sq_CreatePooledObject(ani,true);
	pooledObj = sq_SetEnumDrawLayer(pooledObj, ENUM_DRAWLAYER_BOTTOM);
	pooledObj.setCurrentPos(obj.getXPos() ,obj.getYPos() + 1,obj.getZPos() );
	pooledObj.setCurrentDirection(obj.getDirection());
	sq_AddObject(obj,pooledObj,2,false);	
}



function createShowDown1ST_Back(obj)
{
	if(!obj || !sq_IsMyControlObject(obj) )
	return ;

	local ani = sq_CreateAnimation("","character/swordman/effect/animation/atshowdown/1st/showdown1stwireback_00.ani");
	local pooledObj = sq_CreatePooledObject(ani,true);
	//pooledObj = sq_SetEnumDrawLayer(pooledObj, ENUM_DRAWLAYER_BOTTOM);
	pooledObj.setCurrentPos(obj.getXPos() ,obj.getYPos() - 1,obj.getZPos() );
	pooledObj.setCurrentDirection(obj.getDirection());
	sq_AddObject(obj,pooledObj,2,false);	
}


function createShowDown1ST_Back2(obj)
{
	if(!obj || !sq_IsMyControlObject(obj) )
	return ;

	local ani = sq_CreateAnimation("","character/swordman/effect/animation/atshowdown/1st/showdown1stback_00.ani");
	local pooledObj = sq_CreatePooledObject(ani,true);
	pooledObj = sq_SetEnumDrawLayer(pooledObj, ENUM_DRAWLAYER_BOTTOM);
	pooledObj.setCurrentPos(obj.getXPos() ,obj.getYPos() - 2,obj.getZPos() );
	pooledObj.setCurrentDirection(obj.getDirection());
	sq_AddObject(obj,pooledObj,2,false);	
}



function createShowDown2ST_Back(obj)
{
	if(!obj || !sq_IsMyControlObject(obj) )
	return ;

	local ani = sq_CreateAnimation("","character/swordman/effect/animation/atshowdown/2st/showdown2stwireback_00.ani");
	local pooledObj = sq_CreatePooledObject(ani,true);
	//pooledObj = sq_SetEnumDrawLayer(pooledObj, ENUM_DRAWLAYER_BOTTOM);
	pooledObj.setCurrentPos(obj.getXPos() ,obj.getYPos() - 2,obj.getZPos() );
	pooledObj.setCurrentDirection(obj.getDirection());
	sq_AddObject(obj,pooledObj,2,false);	
}

function createShowDown2ST_Front(obj)
{
	if(!obj || !sq_IsMyControlObject(obj) )
	return ;

	local ani = sq_CreateAnimation("","character/swordman/effect/animation/atshowdown/2st/showdown2stwirefront_00.ani");
	local pooledObj = sq_CreatePooledObject(ani,true);
	//pooledObj = sq_SetEnumDrawLayer(pooledObj, ENUM_DRAWLAYER_BOTTOM);
	pooledObj.setCurrentPos(obj.getXPos() ,obj.getYPos() + 2,obj.getZPos() );
	pooledObj.setCurrentDirection(obj.getDirection());
	sq_AddObject(obj,pooledObj,2,false);	
}



function createShowDown3ST_Back2(obj)
{
	if(!obj || !sq_IsMyControlObject(obj) )
	return ;

	local ani = sq_CreateAnimation("","character/swordman/effect/animation/atshowdown/3st/showdown3stback_00.ani");
	local pooledObj = sq_CreatePooledObject(ani,true);
	pooledObj = sq_SetEnumDrawLayer(pooledObj, ENUM_DRAWLAYER_BOTTOM);
	pooledObj.setCurrentPos(obj.getXPos() ,obj.getYPos() + 2,obj.getZPos() );
	pooledObj.setCurrentDirection(obj.getDirection());
	sq_AddObject(obj,pooledObj,2,false);	
}



function createShowDown3ST_Back(obj)
{
	if(!obj || !sq_IsMyControlObject(obj) )
	return ;

	local ani = sq_CreateAnimation("","character/swordman/effect/animation/atshowdown/3st/showdown3stwireback_00.ani");
	local pooledObj = sq_CreatePooledObject(ani,true);
	//pooledObj = sq_SetEnumDrawLayer(pooledObj, ENUM_DRAWLAYER_BOTTOM);
	pooledObj.setCurrentPos(obj.getXPos() ,obj.getYPos() - 1,obj.getZPos() );
	pooledObj.setCurrentDirection(obj.getDirection());
	sq_AddObject(obj,pooledObj,2,false);	
}


function createShowDown3ST_Front(obj)
{
	if(!obj || !sq_IsMyControlObject(obj) )
	return ;

	local ani = sq_CreateAnimation("","character/swordman/effect/animation/atshowdown/3st/showdown3stwirefront_00.ani");
	local pooledObj = sq_CreatePooledObject(ani,true);
	//pooledObj = sq_SetEnumDrawLayer(pooledObj, ENUM_DRAWLAYER_BOTTOM);
	pooledObj.setCurrentPos(obj.getXPos() ,obj.getYPos() + 1,obj.getZPos() );
	pooledObj.setCurrentDirection(obj.getDirection());
	sq_AddObject(obj,pooledObj,2,false);	
}

function createShowDown3ST_Front2(obj)
{
	if(!obj || !sq_IsMyControlObject(obj) )
	return ;

	local ani = sq_CreateAnimation("","character/swordman/effect/animation/atshowdown/3st/showdown3stfront_00.ani");
	local pooledObj = sq_CreatePooledObject(ani,true);
	pooledObj = sq_SetEnumDrawLayer(pooledObj, ENUM_DRAWLAYER_BOTTOM);
	pooledObj.setCurrentPos(obj.getXPos() ,obj.getYPos() + 1,obj.getZPos() );
	pooledObj.setCurrentDirection(obj.getDirection());
	sq_AddObject(obj,pooledObj,2,false);	
}

function createShowDown3ST_Cover(obj)
{
	if(!obj || !sq_IsMyControlObject(obj) )
	return ;

	local ani = sq_CreateAnimation("","character/swordman/effect/animation/atshowdown/3st/showdown3stcover_00.ani");
	local pooledObj = sq_CreatePooledObject(ani,true);
	pooledObj = sq_SetEnumDrawLayer(pooledObj, ENUM_DRAWLAYER_COVER);
	pooledObj.setCurrentPos(obj.getXPos() ,obj.getYPos() + 1,obj.getZPos() );
	pooledObj.setCurrentDirection(obj.getDirection());
	sq_AddObject(obj,pooledObj,2,false);	
}
